package com.funny.learning.english.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.funny.learning.english.R;

public class LangNgheVaVietGridAdapter extends BaseAdapter{
	private LayoutInflater inflater;
	private ArrayList<String> arrData;
	
	private ClickTvListener clickTvListener;
	
	public LangNgheVaVietGridAdapter(Context context, ArrayList<String> arrData) {
		inflater = LayoutInflater.from(context);
		
		this.arrData = arrData;
	}
	
	@Override
	public int getCount() {
		return arrData.size();
	}

	@Override
	public String getItem(int arg0) {
		return arrData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		if(convertView == null){
			convertView = inflater.inflate(R.layout.lang_nghe_viet_grid_item, null);
		}
		TextView tvWordItem = (TextView)convertView.findViewById(R.id.tv1);
		
		final String str = arrData.get(arg0);
		
		if(!str.equals("")){
			tvWordItem.setText(str);
		}
		
		tvWordItem.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				clickTvListener.onclick(arg0, str);
			}
		});
		return convertView;
	}
	
	
	
	public ClickTvListener getClickTvListener() {
		return clickTvListener;
	}

	public void setClickTvListener(ClickTvListener clickTvListener) {
		this.clickTvListener = clickTvListener;
	}



	public interface ClickTvListener{
		void onclick(View view, String str);
	}

}
